package com.xszx.business.controller.admin;

import com.xszx.server.dto.AjaxJson;
import com.xszx.server.dto.Page;
import com.xszx.server.entity.CourseContentFile;
import com.xszx.server.service.CourseContentFileService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/courseContentFile")
public class CourseContentFileController {
    @Resource
    private CourseContentFileService courseContentFileService;

    @GetMapping("/getAllCourseContentFiles")
    public AjaxJson getAllCourseContentFiles(String courseId){
        return AjaxJson.success().put("courseContentFiles",courseContentFileService.getAllCourseContentFiles(courseId));
    }

    @GetMapping("/getCourseContentFile")
    public AjaxJson getCourseContentFile(String id){
        return AjaxJson.success().put("courseContentFiles",courseContentFileService.getCourseContentFile(id));
    }

    @PostMapping("/save")
    public AjaxJson save(@RequestBody CourseContentFile courseContentFile){
        return AjaxJson.success(courseContentFileService.saveOrUpdate(courseContentFile));
    }

    @PostMapping("/deleteCourseContentFile/{id}")
    public AjaxJson deleteCourseContentFile(@PathVariable("id") String id){
        int result = courseContentFileService.del(id);
        if(result>0){
            return AjaxJson.success("删除成功");
        }else{
            return AjaxJson.error("删除失败");
        }
    }
}
